package com.hmkj.admin.controller.report;

import com.hmkj.admin.controller.BaseController;
import com.hmkj.admin.controller.GenericController;
import com.hmkj.common.entity.ResultEntity;
import com.hmkj.common.entity.dtgrid.DtGrid;
import com.hmkj.common.entity.export.ExportUtils;
import com.hmkj.core.po.dailyReport.DailyReport;
import com.hmkj.core.service.dailyReport.DailyReportService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping(BaseController.BASE_URI)
public class DailyReportJsonController extends GenericController<Integer, DailyReport> {

    @Autowired
    private DailyReportService dailyReportService;

    /**
     * 日报json数据
     *
     * @param dtGridPager
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "/dayReport/list.json", method = RequestMethod.POST)
    @RequiresPermissions("sys:dailyReport:list")
    public DtGrid listJson(String dtGridPager) throws Exception{
        return dailyReportService.getDtGridList(dtGridPager, DailyReport.class);

    }

    /**
     * 列表导出
     *
     * @param dtGridPager
     * @return
     */
    @ResponseBody
    @RequestMapping(value = "dayReport/export.json", method = RequestMethod.POST)
    public ResultEntity export(String dtGridPager, HttpServletRequest request, HttpServletResponse response) throws Exception {
        // 执行导出
        ExportUtils.export(request, response, dailyReportService.getDtGridListExport(dtGridPager,DailyReport.class));
        return ok();
    }
}
